package com.hunttown.mes.manage.controller._basic;

import com.hunttown.mes.common.utils.ChineseToPinyinUtils;
import com.hunttown.mes.common.utils.StringUtils;
import com.hunttown.mes.manage.service.AnalysisRegionManageService;
import com.hunttown.mes.rpc.domain.AnalysisRegionDTO;
import com.hunttown.mes.rpc.domain.query.AnalysisRegionDTOQuery;
import com.hunttown.common.domain.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @title: 全国行政区划数据（省、市、县(区)、镇(街道)、村）
 * @author: wangjunfu
 * @date: 2020年10月09日 10:25
 * @description:
 */
@Controller
@RequestMapping(value = "/basic/region")
public class RegionController {

    private final static Logger logger = LoggerFactory.getLogger(RegionController.class);

    private final AnalysisRegionManageService analysisRegionService;

    @Autowired
    public RegionController(AnalysisRegionManageService analysisRegionService) {
        this.analysisRegionService = analysisRegionService;
    }

    //region 获取当前行政单位的下级

    /**
     * 获取当前行政单位的下级
     *
     * @param parentId 当前区域ID
     * @return
     */
    @RequestMapping(value = "/getSubRetion", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> getSubRetion(Integer parentId) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("returnCode", 0);

        if (parentId == null) {
            parentId = 0;
        }

        if (parentId > 0) {
            AnalysisRegionDTOQuery query_region = new AnalysisRegionDTOQuery();
            query_region.setParentId(parentId);
            query_region.setPageSize(1000);
            Page<AnalysisRegionDTO> regionPage = analysisRegionService.getForPage(query_region);

            if (regionPage != null) {
                map.put("regionList", regionPage.getItems());
            }

            map.put("returnCode", 1);
        }

        return map;
    }

    //endregion

}
